﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace App
{
    public partial class AddPlayers : System.Web.UI.Page
    {
        AppLib.Event Event;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Common.GetLoggedUser(this.Page) == null)
            {
                Response.Redirect("Login.aspx");
                return;
            }

            Event = MidApp.ManageEvent.GetEventByID(int.Parse(Server.HtmlEncode(Request.Cookies["AddPlay"].Value)));
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {

            RepeaterUsers.DataSource = MidApp.ManageParticipate.GetParticipantsOnEvent(Event.EventID);
            RepeaterUsers.DataBind();

            RepeaterAddUsers.DataSource = MidApp.ManageIsMember.GetNonParticipant(MidApp.ManagePossession.GetTeamInChargeOfEvent(Event.EventID).TeamID, Event.EventID);
            RepeaterAddUsers.DataBind();

        }
        //obsluha tlacitka pro zobrazeni detailu hrace
        protected void LinkButtonUserInfo_Click(object sender, EventArgs e)
        {
            Response.Cookies["UserDetail"].Value = ((LinkButton)sender).CommandArgument;
            Response.Redirect("UserDetail.aspx");
        }
        //metoda vraci nick prihlaseneho hrace na akci
        protected string GetUserNick(object sender)
        {
            var aux = (AppLib.Participate)sender;

            return aux.User.Nick;
        }
        //metoda vraci nick prihlaseneho hrace na akci
        protected string GetUserNickA(object sender)
        {
            var aux = sender as AppLib.IsMember;

            return aux.User.Nick;
        }
        //metoda vraci jmeno a prijmeni
        protected string GetUserNameSurname(object sender)
        {
            var aux = (AppLib.Participate)sender;

            string name = aux.User.Name + " " + aux.User.Surname;

            return name;
        }
        //metoda vraci jmeno a prijmeni
        protected string GetUserNameSurnameB(object sender)
        {
            var aux = sender as AppLib.IsMember;

            string name = aux.User.Name + " " + aux.User.Surname;

            return name;
        }
        //metoda vraci string hodnotu ID uzivatele
        protected string GetUserID(object sender)
        {
            var aux = (AppLib.Participate)sender;

            return aux.UserID.ToString();
        }

        protected string GetMemberAvatar2(object sender)
        {
            var pom = (AppLib.IsMember)sender;
            return MidApp.ManageUser.GetUserImage(pom.UserID);
        }
        protected string GetMemberEmail2(object sender)
        {
            var pom = (AppLib.IsMember)sender;
            return (MidApp.ManageUser.GetUserByID(pom.UserID)).PrimaryEmail;
        }

        protected string GetMemberAvatar(object sender)
        {
            var pom = (AppLib.Participate)sender;
            return MidApp.ManageUser.GetUserImage(pom.UserID);
        }
        protected string GetMemberEmail(object sender)
        {
            var pom = (AppLib.Participate)sender;
            return (MidApp.ManageUser.GetUserByID(pom.UserID)).PrimaryEmail;
        }

        protected void LinkButtonAdd_Click(object sender, EventArgs e)
        {
            var UserID = int.Parse(((LinkButton)sender).CommandArgument);
            var TeamID = MidApp.ManagePossession.GetTeamInChargeOfEvent(Event.EventID).TeamID;
            
            AppLib.Detail newDetail = new AppLib.Detail();
            newDetail.Amount = "-" + MidApp.ManageEvent.GetEventByID(Event.EventID).Price.ToString();
            newDetail.Detail1 = "Strhnuto za dodatečné zapsání na akci " + MidApp.ManageEvent.GetEventByID(Event.EventID).EventName;
            newDetail.Date = DateTime.Today;


            MidApp.ManageParticipate.SignUserToEvent(Event.EventID, UserID, TeamID, newDetail);
        }
    }
}